{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:24:32.779551Z",
     "start_time": "2019-03-20T09:24:30.316404Z"
    }
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Using TensorFlow backend.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "matchzoo version 2.1.0\n"
     ]
    }
   ],
   "source": [
    "import keras\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matchzoo as mz\n",
    "import json\n",
    "print('matchzoo version', mz.__version__)\n",
    "print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:24:33.363273Z",
     "start_time": "2019-03-20T09:24:32.781793Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "data loading ...\n",
      "data loaded as `train_pack_raw` `dev_pack_raw` `test_pack_raw`\n"
     ]
    }
   ],
   "source": [
    "print('data loading ...')\n",
    "train_pack_raw = mz.datasets.wiki_qa.load_data('train', task='ranking')\n",
    "dev_pack_raw = mz.datasets.wiki_qa.load_data('dev', task='ranking', filtered=True)\n",
    "test_pack_raw = mz.datasets.wiki_qa.load_data('test', task='ranking', filtered=True)\n",
    "print('data loaded as `train_pack_raw` `dev_pack_raw` `test_pack_raw`')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:24:33.370082Z",
     "start_time": "2019-03-20T09:24:33.365067Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "`ranking_task` initialized with metrics [normalized_discounted_cumulative_gain@3(0.0), normalized_discounted_cumulative_gain@5(0.0), mean_average_precision(0.0)]\n"
     ]
    }
   ],
   "source": [
    "ranking_task = mz.tasks.Ranking(loss=mz.losses.RankHingeLoss())\n",
    "ranking_task.metrics = [\n",
    "    mz.metrics.NormalizedDiscountedCumulativeGain(k=3),\n",
    "    mz.metrics.NormalizedDiscountedCumulativeGain(k=5),\n",
    "    mz.metrics.MeanAveragePrecision()\n",
    "]\n",
    "print(\"`ranking_task` initialized with metrics\", ranking_task.metrics)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:24:42.021896Z",
     "start_time": "2019-03-20T09:24:33.374357Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "loading embedding ...\n",
      "embedding loaded as `glove_embedding`\n"
     ]
    }
   ],
   "source": [
    "print(\"loading embedding ...\")\n",
    "glove_embedding = mz.datasets.embeddings.load_glove_embedding(dimension=300)\n",
    "print(\"embedding loaded as `glove_embedding`\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2019-03-20T09:24:42.033039Z",
     "start_time": "2019-03-20T09:24:42.025321Z"
    },
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def append_params_to_readme(model):\n",
    "    import tabulate\n",
    "    \n",
    "    with open('README.rst', 'a+') as f:\n",
    "        subtitle = model.params['model_class'].__name__\n",
    "        line = '#' * len(subtitle)\n",
    "        subtitle = subtitle + '\\n' + line + '\\n\\n'\n",
    "        f.write(subtitle)\n",
    "        \n",
    "        df = model.params.to_frame()[['Name', 'Value']]\n",
    "        table = tabulate.tabulate(df, tablefmt='rst', headers='keys') + '\\n\\n'\n",
    "        f.write(table)"
   ]
  }
 ],
 "metadata": {
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  },
  "toc": {
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": "block",
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
